import Vue from "vue";
import Router from "vue-router";
import VueCookie from "vue-cookies";
import NProgress from "nprogress"; //进度条
import "nprogress/nprogress.css";
Vue.use(Router);
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
const myRouter = new Router({
  mode: "hash",
  scrollBehavior: () => ({ y: 0 }),
  routes: [
    // 可视化页面
    // {
    //   path: "/overview",
    //   name: "overview",
    //   // redirect: '/home',//暂时屏蔽该路由
    //   component: () => import("@/views/overview/index"),
    // },
    // 登录
    {
      path: "/login",
      name: "login",
      component: () => import("@/views/login/index"),
      meta: { title: "登录" },
    },
    // 404
    {
      path: "/404",
      name: "404",
      component: () => import("@/views/components/404"),
    },
    {
      path: "/",
      redirect: "/home",
      component: () => import("@/views/layout/Layout"),
      children: [
        // 首页
        {
          path: "/home",
          component: () => import("@/views/modules/Home/index"),
          name: "Home",
          meta: { title: "首页" },
        },
        // 报告中心
        {
          path: "/report",
          redirect: "/report/index",
          component: () => import("@/views/modules/Report/index"),
          name: "report",
          meta: { title: "报告中心" },
          children: [
            {
              path: "index",
              component: () => import("@/views/modules/Report/child/index"),
              name: "reportIndex",
              meta: { title: "" },
            },
            // 期刊
            {
              path: "journal/:id",
              component: () => import("@/views/modules/Report/child/Journal"),
              name: "reportJournal",
              meta: { title: "" },
            },
            // 内部报告详情页
            {
              path: "contentDetail/:id",
              component: () =>
                import("@/views/modules/Report/child/contentDetail"),
              name: "reportContentDetail",
              meta: { title: "" },
            },
          ],
        },

        {
          path: "/DC",
          redirect: "/DC/main",
          component: () => import("@/views/modules/DataCenter/index"),
          name: "DC",
          meta: { title: "数据中心" },
          children: [
            // 综合查询
            {
              path: "comprehensive",
              component: () =>
                import("@/views/modules/DataCenter/child/comprehensive/index"),
              name: "DCComprehensive",
              meta: { title: "" },
            },
            // 数据中心父组件 包含专利库、文献库、成果库、项目库、标准库等页面
            {
              path: "main",
              component: () => import("@/views/modules/DataCenter/child/main"),
              name: "DCMain",
              meta: { title: "" },
            },
            // 封装详情页 包括专利、文献、成果、项目、标准等所有详情
            {
              path: "DataCenterDetail",
              component: () =>
                import("@/views/modules/DataCenter/child/base/detail/index"),
              name: "DataCenterDetail",
              meta: { title: "" },
            },
          ],
        },
        // 企业画像
        {
          path: "/EI",
          redirect: "/EI/search",
          component: () => import("@/views/modules/PortraitEnterprise/index"),
          name: "EI",
          meta: { title: "企业画像" },
          children: [
            {
              path: "search",
              component: () =>
                import("@/views/modules/PortraitEnterprise/child/Search"),
              name: "EISearch",
              meta: { title: "企业画像--检索页面" },
            },
            {
              path: "searchResult",
              component: () =>
                import(
                  "@/views/modules/PortraitEnterprise/child/SearchResult/index"
                ),
              name: "EISearchResult",
              meta: { title: "企业画像--列表页面" },
            },
            {
              path: "qy",
              component: () =>
                import(
                  "@/views/modules/PortraitEnterprise/child/SearchResult/qy"
                ),
              name: "EIQy",
              meta: { title: "企查查--企业画像" },
            },
          ],
        },
        // 人才画像
        {
          path: "/PD",
          redirect: "/PD/search",
          component: () => import("@/views/modules/PortraitTalent/index"),
          name: "PD",
          meta: { title: "人才画像" },
          children: [
            {
              path: "search",
              // component: () =>
              //   import("@/views/modules/PortraitTalent/child/Search"),
              component: () =>
                import("@/views/modules/PortraitTalent/child/pt"),
              name: "PDSearch",
              meta: { title: "人才画像" },
            },
            {
              path: "moreList",
              // component: () =>
              //   import("@/views/modules/PortraitTalent/child/Search"),
              component: () =>
                import("@/views/modules/PortraitTalent/child/moreList"),
              name: "moreList",
              meta: { title: "人才画像" },
            },
            {
              path: "talentList",
              // component: () =>
              //   import("@/views/modules/PortraitTalent/child/Search"),
              component: () =>
                import("@/views/modules/PortraitTalent/child/talentList"),
              name: "talentList",
              meta: { title: "人才画像" },
            },
            {
              path: "detail",
              // component: () =>
              //   import("@/views/modules/PortraitTalent/child/Search"),
              component: () =>
                import("@/views/modules/PortraitTalent/child/detail"),
              name: "detail",
              meta: { title: "人才画像" },
            },
            // {
            //   path: "searchResult",
            //   component: () =>
            //     import(
            //       "@/views/modules/PortraitTalent/child/SearchResult/index"
            //     ),
            //   name: "PDSearchResult",
            //   meta: { title: "人才画像" },
            // },
          ],
        },
        // 资讯
        {
          path: "Consult",
          component: () => import("@/views/modules/Consult/index"),
          name: "Consult",
          meta: { title: "动态资讯" },
        },
        // 资讯 - 详情
        {
          path: "ConsultDetail",
          component: () => import("@/views/modules/Consult/detail.vue"),
          name: "ConsultDetail",
          meta: { title: "资讯详情" },
        },
        // 数据分析 - 包含 专利 、论文
        {
          path: "analysis",
          name: "Analysis",
          component: () => import("@/views/modules/Analysis/index.vue"),
        },
        // 其他分析 包含技术前沿、技术主题、技术成熟度
        {
          path: "/TecAnalysis",
          redirect: "/TecAnalysis/technologyFrontier",
          component: () =>
            import("@/views/modules/Analysis/otherAnalysis/index"),
          name: "TecAnalysis",
          meta: { title: "技术分析" },
          children: [
            // 前沿技术
            {
              path: "technologyFrontier",
              component: () =>
                import(
                  "@/views/modules/Analysis/otherAnalysis/technologyFrontier.vue"
                ),
              name: "technologyFrontier",
              meta: { title: "技术前沿" },
            },
            // 技术成熟度
            {
              path: "technologyMaturity",
              component: () =>
                import(
                  "@/views/modules/Analysis/otherAnalysis/technologyMaturity.vue"
                ),
              name: "technologyMaturity",
              meta: { title: "技术成熟度" },
            },
            // 技术发展趋势
            {
              path: "technologyTopicTrends",
              component: () =>
                import(
                  "@/views/modules/Analysis/otherAnalysis/technologyTopicTrends.vue"
                ),
              name: "technologyTopicTrends",
              meta: { title: "技术发展趋势" },
            },
            // 专利技术路线图
            {
              path: "patentRoadmap",
              component: () =>
                import(
                  "@/views/modules/Analysis/otherAnalysis/patentRoadmap.vue"
                ),
              name: "patentRoadmap",
              meta: { title: "专利技术路线图" },
            },
          ],
        },

        // 服务端使用 用于无头浏览器导出报告用 -- 勿动
        {
          path: "downLoadIndex",
          name: "downLoadIndex",
          component: () => import("@/views/modules/Analysis/downLoadIndex.vue"),
        },
        // 产业技术链
        {
          path: "/IC",
          name: "IndustrialChain",
          redirect: "/IC/search",
          component: () => import("@/views/modules/IndustrialChain/index.vue"),
          meta: { title: "产业技术链" },
          children: [
            // 检索
            {
              path: "search",
              component: () =>
                import("@/views/modules/IndustrialChain/child/search.vue"),
              name: "ICSearch",
            },
            {
              path: "detail",
              component: () =>
                import("@/views/modules/IndustrialChain/child/detail.vue"),
              name: "ICDetail",
            },
          ],
        },
        // 个人中心
        {
          path: "/personal",
          name: "personal",
          component: () => import("@/views/modules/Personal/index.vue"),
          meta: { title: "个人中心" },
          children: [],
        },
        // 新企业画像
        {
          path: "/assessment",
          // component: Assessment,
          component: () => import("@/views/modules/Science/assessment/Index"),
          children: [
            // 技术概览
            {
              path: "technologyOverview",
              name: "technologyOverview",
              // component: TechnologyOverview,
              component: () =>
                import("@/views/modules/Science/TechnologyOverview"),
              meta: {
                index: 0,
              },
            },
            // 技术分析
            {
              path: "technicalAnalysis",
              name: "technicalAnalysis",
              // component: TechnicalAnalysis,
              component: () =>
                import("@/views/modules/Science/TechnicalAnalysis"),
              meta: {
                index: 0,
              },
            },
            // 专利列表
            {
              path: "patent",
              name: "patentList",
              // component: PatentList,
              component: () => import("@/views/modules/Science/PatentList"),
              meta: {
                index: 1,
              },
            },
            // 专利运营
            {
              path: "highvalue",
              name: "highValueMining",
              // component: HighValueMining,
              component: () =>
                import("@/views/modules/Science/HighValueMining"),
              meta: {
                index: 1,
              },
            },
            // 专利详情
            {
              path: "patent/details",
              name: "patentDetails",
              // component: PatentDetails,
              component: () => import("@/views/modules/Science/PatentDetails"),
              meta: {
                index: 1,
              },
            },
            // 核心团队
            {
              path: "coreTeam",
              name: "coreTeam",
              // component: CoreTeam,
              component: () => import("@/views/modules/Science/team/CoreTeam"),
              meta: {
                index: 2,
              },
            },
            // 更多人才
            {
              path: "moreTalent",
              name: "moreTalent",
              // component: MoreTalent,
              component: () =>
                import("@/views/modules/Science/team/MoreTalent"),
              meta: {
                index: 2,
              },
            },
            // 人才详情
            {
              path: "talentDetails",
              name: "talentDetails",
              // component: TalentDetails,
              component: () =>
                import("@/views/modules/Science/team/detail/TalentDetails"),
              meta: {
                index: 2,
              },
            },
            // 技术对比
            {
              path: "technicalComparison",
              name: "technicalComparison",
              // component: TechnicalComparison,
              component: () =>
                import("@/views/modules/Science/TechnicalComparison"),
              meta: {
                index: 3,
              },
            },
            // 基本信息
            {
              path: "basic",
              name: "basic",
              // component: Basic,
              component: () => import("@/views/modules/Science/basic/Index"),
            },
            // 风险信息
            {
              path: "riskmanage",
              name: "riskmanage",
              // component: Riskmanage
              component: () =>
                import("@/views/modules/Science/riskmanage/Index"),
            },
            // 新闻信息
            {
              path: "news",
              name: "news",
              // component: News
              component: () => import("@/views/modules/Science/news/Index"),
            },
          ],
        },

        // 情报检索
        // {
        //   path: "/IR",
        //   redirect: "/IR/search",
        //   component: () => import("@/views/modules/IR/index"),
        //   name: "IR",
        //   meta: { title: "情报检索" },
        //   children: [
        //     // 检索
        //     {
        //       path: "search",
        //       component: () => import("@/views/modules/IR/child/Search"),
        //       name: "IRSearch",
        //       meta: { title: "" },
        //     },
        //     // 检索综合页
        //     {
        //       path: "overview",
        //       component: () =>
        //         import("@/views/modules/IR/child/SearchResult/Overview"),
        //       name: "IROverview",
        //       meta: { title: "" },
        //     },
        //     // 检索结果页
        //     {
        //       path: "searchResult",
        //       component: () =>
        //         import("@/views/modules/IR/child/SearchResult/index"),
        //       name: "IRSearchResult",
        //       meta: { title: "" },
        //     },
        //   ],
        // },
        // 数据中心
        // 能源产业
        // {
        //   path: "/EnergyIndustry",
        //   component: () => import("@/views/modules/EnergyIndustry/index"),
        //   name: "EnergyIndustry",
        //   meta: { title: "能源产业" },
        // },
        // 能源技术
        // {
        //   path: "/EnergyTechnology",
        //   component: () => import("@/views/modules/EnergyTechnology/index"),
        //   name: "EnergyTechnology",
        //   meta: { title: "能源产业" },
        //   children: [
        //     // 技术链
        //     {
        //       path: "IndustrialTechnologyChain",
        //       component: () =>
        //         import(
        //           "@/views/modules/EnergyTechnology/IndustrialTechnologyChain/index"
        //         ),
        //       name: "IndustrialTechnologyChain",
        //       meta: { title: "技术链" },
        //     },
        //     {
        //       path: "PersAndCompList",
        //       component: () =>
        //         import(
        //           "@/views/modules/EnergyTechnology/IndustrialTechnologyChain/list"
        //         ),
        //       name: "PersAndCompList",
        //       meta: { title: "技术链" },
        //     },
        //     // 技术价值评估(TODO)
        //     {
        //       path: "TechnicalValuation",
        //       redirect: "TechnicalValuation/list",
        //       component: () =>
        //         import(
        //           "@/views/modules/EnergyTechnology/TechnicalValuation/index"
        //         ),
        //       name: "TechnicalValuation",
        //       meta: { title: "技术价值评估" },
        //       children: [
        //         // 列表
        //         // {
        //         //   path: 'list',
        //         //   component: () => import('@/views/modules/EnergyTechnology/TechnicalValuation/List/index'),
        //         //   name: 'TechnicalValuationList',
        //         //   meta: { title: '技术价值评估' },
        //         // },
        //         // 专利详情
        //         {
        //           path: "detail",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyTechnology/TechnicalValuation/Details/index"
        //             ),
        //           name: "TechnicalValuationDetail",
        //           meta: { title: "专利详情" },
        //         },
        //       ],
        //     },
        //   ],
        // },
        // 能源企业
        // {
        //   path: "EnergyEnterprise",
        //   redirect: "EnergyEnterprise/list",
        //   component: () => import("@/views/modules/EnergyEnterprise/index"),
        //   name: "EnergyEnterprise",
        //   meta: { title: "能源企业" },
        //   children: [
        //     // 能源企业-详情
        //     {
        //       path: "detail",
        //       redirect: "detail/technologyOver",
        //       component: () =>
        //         import("@/views/modules/EnergyEnterprise/Details/index"),
        //       name: "EnergyEnterpriseDetails",
        //       meta: { title: "企业详情" },
        //       children: [
        //         {
        //           path: "technologyOver",
        //           name: "technologyOver",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/technologyOver/index"
        //             ),
        //           meta: { title: "企业详情-技术总览" },
        //         },
        //         {
        //           path: "technicalAnalysis",
        //           name: "technicalAnalysis",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/technicalAnalysis/index"
        //             ),
        //           meta: { title: "企业详情-技术分析" },
        //         },
        //         {
        //           path: "informationOver",
        //           name: "informationOver",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/informationOver/index"
        //             ),
        //           meta: { title: "企业详情-信息概览" },
        //         },
        //         {
        //           path: "business",
        //           name: "business",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/business/index"
        //             ),
        //           meta: { title: "企业详情-工商信息" },
        //         },
        //         {
        //           path: "stockRight",
        //           name: "stockRight",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/stockRight/index"
        //             ),
        //           meta: { title: "企业详情-股权信息" },
        //         },
        //         {
        //           path: "investmentDistribution",
        //           name: "investmentDistribution",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/investmentDistribution/index"
        //             ),
        //           meta: { title: "企业详情-投资分布" },
        //         },
        //         {
        //           path: "partentList",
        //           name: "partentList",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/partentList/index"
        //             ),
        //           meta: { title: "企业详情-专利列表" },
        //         },
        //         {
        //           path: "riskInformation",
        //           name: "riskInformation",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/riskInformation/index"
        //             ),
        //           meta: { title: "企业详情-风险信息" },
        //         },
        //         {
        //           path: "riskAnalysis",
        //           name: "riskAnalysis",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/riskAnalysis/index"
        //             ),
        //           meta: { title: "企业详情-风险分析" },
        //         },
        //         {
        //           path: "publicSentiment",
        //           name: "publicSentiment",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/publicSentiment/index"
        //             ),
        //           meta: { title: "企业详情-企业舆情" },
        //         },
        //         {
        //           path: "auth",
        //           name: "auth",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/auth/index"
        //             ),
        //           meta: { title: "企业详情-转让/授权/质押" },
        //         },
        //         {
        //           path: "patentDetail",
        //           name: "patentDetail",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyEnterprise/Details/patentDetail/index"
        //             ),
        //           meta: { title: "企业详情-专利详情" },
        //         },
        //       ],
        //     },
        //   ],
        // },
        // 下载中心
        // {
        //   path: "DownloadCenter",
        //   name: "centerIndex",
        //   redirect: "/DownloadCenter/basicInfo",
        //   component: () => import("@/views/modules/DownloadCenter/index.vue"),
        //   children: [
        //     // 下载中心
        //     {
        //       path: "downloadCenter",
        //       name: "downloadCenter",
        //       component: () =>
        //         import("@/views/modules/DownloadCenter/DownloadCenter.vue"),
        //       meta: {
        //         navType: "wide",
        //       },
        //     },
        //   ],
        // },
        // 人才画像
        // {
        //   path: "EnergyTalent",
        //   redirect: "EnergyTalent/list",
        //   component: () => import("@/views/modules/EnergyTalent/index"),
        //   name: "EnergyTalent",
        //   meta: { title: "人才画像" },
        //   children: [
        //     // 人才画像-详情
        //     {
        //       path: "detail",
        //       // redirect: 'EnergyTalent/detail/introduction',
        //       name: "EnergyTalentDetail",
        //       component: () =>
        //         import("@/views/modules/EnergyTalent/Details/index"),
        //       meta: { title: "人才画像" },
        //       children: [
        //         // 人才简介
        //         {
        //           path: "introduction",
        //           name: "EnergyTalentDetailIntroduction",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyTalent/Details/introduction/index"
        //             ),
        //           meta: { title: "人才简介" },
        //         },
        //         // 科研概况
        //         {
        //           path: "situation",
        //           name: "EnergyTalentDetailSituation",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyTalent/Details/situation/index"
        //             ),
        //           meta: { title: "科研概况" },
        //         },
        //         // 科研成果
        //         {
        //           path: "achievement",
        //           name: "EnergyTalentDetailAchievement",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyTalent/Details/achievement/index"
        //             ),
        //           meta: { title: "科研成果" },
        //         },
        //         // 关联企业
        //         {
        //           path: "associated",
        //           name: "EnergyTalentDetailAssociated",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyTalent/Details/associated/index"
        //             ),
        //           meta: { title: "关联企业" },
        //         },
        //         // 社会影响力
        //         {
        //           path: "influence",
        //           name: "EnergyTalentDetailInfluence",
        //           component: () =>
        //             import(
        //               "@/views/modules/EnergyTalent/Details/influence/index"
        //             ),
        //           meta: { title: "社会影响力" },
        //         },
        //       ],
        //     },
        //     // 人才画像-专利详情
        //     {
        //       path: "patentDetail",
        //       component: () =>
        //         import("@/views/modules/EnergyTalent/Details/PatentDetail"),
        //       name: "EnergyTalentPatentDetail",
        //       meta: { title: "专利详情" },
        //     },
        //   ],
        // },

        // 行业观点
        // {
        //   path: "IndustryPointOfView",
        //   component: () =>
        //     import("@/views/modules/IndustryPointOfView/index.vue"),
        //   name: "IndustryPointOfView",
        //   meta: { title: "行业观点" },
        // },
        // 行业观点-检索结果
        // {
        //   path: "IndustryPointOfView/result",
        //   component: () =>
        //     import("@/views/modules/IndustryPointOfView/Result.vue"),
        //   name: "IndustryPointOfViewResult",
        //   meta: { title: "行业观点" },
        // },
        // 订阅
        // {
        //   path: "Subscribe",
        //   component: () => import("@/views/modules/Subscribe/index"),
        //   name: "Subscribe",
        //   meta: { title: "订阅" },
        // },
        // 专利档案
        // {
        //   path: "PatentArchives",
        //   name: "PatentArchives",
        //   redirect: "PatentArchives/technologyValue",
        //   component: () => import("@/views/modules/PatentArchives/index.vue"),
        //   children: [
        //     // 技术价值度
        //     {
        //       path: "technologyValue",
        //       name: "PatentArchivesTechnologyValue",
        //       component: () =>
        //         import("@/views/modules/PatentArchives/TechnologyValue.vue"),
        //     },
        //     // 专利价值度
        //     {
        //       path: "patentValue",
        //       name: "PatentArchivesPatentValue",
        //       component: () =>
        //         import("@/views/modules/PatentArchives/PatentValue.vue"),
        //     },
        //   ],
        // },
        // 技术分析
        // {
        //   path: '/TI',
        //   redirect: '/TI/analysis',
        //   component: () => import('@/views/modules/TechnicalIntelligence/index'),
        //   name: 'TI',
        //   meta: { title: '技术分析' },
        //   children: [
        //     {
        //       path: 'analysis',
        //       component: () => import('@/views/modules/TechnicalIntelligence/analysis/index'),
        //       name: 'TIAnalysis',
        //       meta: { title: '' },
        //     }
        //   ]
        // },
        //技术分析
        // {
        //   path: '/TecAnalysis',
        //   redirect: '/TecAnalysis/main',
        //   component: () => import('@/views/modules/TecAnalysis/index'),
        //   name: 'TecAnalysis',
        //   meta: { title: '技术分析' },
        //   children: [
        //     // 技术分析
        //     {
        //       path: 'main',
        //       component: () => import('@/views/modules/TecAnalysis/index'),
        //       name: 'TecAnalysisMain',
        //       meta: { title: '' },
        //     },
        //   ]
        // },
      ],
    },
    {
      // 当没有匹配到正确路由的时候，匹配notOpen组件
      path: "*",
      redirect: "/404",
      hidden: true,
    },
  ],
});
//判断是否存在token
myRouter.beforeEach((to, from, next) => {
  let token = VueCookie.get("token");
  NProgress.start();
  if (
    to.path !== "/login" &&
    to.path !== "/overview" &&
    (!token || !/\S/.test(token))
  ) {
    // next({
    //   name: 'home'
    // })
    NProgress.done(); // 结束Progress
    // if (to.meta.title) {
    //   document.title = to.meta.title
    // }
    next();
  } else {
    // if (to.meta.title) {
    //   document.title = to.meta.title
    // }
    next();
  }
});
myRouter.afterEach(() => {
  NProgress.done(); // 结束Progress
});
export default myRouter;
